package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Language;
import com.ruoyi.system.service.ILanguageService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 编程语言Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/system/language")
public class LanguageController extends BaseController
{
    @Autowired
    private ILanguageService languageService;

    /**
     * 查询编程语言列表
     */
    @PreAuthorize("@ss.hasPermi('system:language:list')")
    @GetMapping("/list")
    public TableDataInfo list(Language language)
    {
        startPage();
        List<Language> list = languageService.selectLanguageList(language);
        return getDataTable(list);
    }

    /**
     * 导出编程语言列表
     */
    @PreAuthorize("@ss.hasPermi('system:language:export')")
    @Log(title = "编程语言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Language language)
    {
        List<Language> list = languageService.selectLanguageList(language);
        ExcelUtil<Language> util = new ExcelUtil<Language>(Language.class);
        util.exportExcel(response, list, "编程语言数据");
    }

    /**
     * 获取编程语言详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:language:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(languageService.selectLanguageById(id));
    }

    /**
     * 新增编程语言
     */
    @PreAuthorize("@ss.hasPermi('system:language:add')")
    @Log(title = "编程语言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Language language)
    {
        return toAjax(languageService.insertLanguage(language));
    }

    /**
     * 修改编程语言
     */
    @PreAuthorize("@ss.hasPermi('system:language:edit')")
    @Log(title = "编程语言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Language language)
    {
        return toAjax(languageService.updateLanguage(language));
    }

    /**
     * 删除编程语言
     */
    @PreAuthorize("@ss.hasPermi('system:language:remove')")
    @Log(title = "编程语言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(languageService.deleteLanguageByIds(ids));
    }
}
